package com.ly.hotel.util;

import android.app.Instrumentation;
import android.util.Log;

/**
 * @author Administrator
 * 与触摸有关的工具
 */
public class TouchUtil {
	
	private static long lastClickTime;
	private static boolean sendKeyLock = false;
    public static boolean isFastDoubleClick() {
            long time = System.currentTimeMillis();
			long timeD = time - lastClickTime;
            if (timeD >= 0 && timeD <= 400) {
                return true;
            } else {
                lastClickTime = time;
                return false;
            }
        }
    
	 /**
	  * 模拟产生一个键盘的按键事件
	 * @param keyCode keyEvent枚举的值
	 */
	public static void sendKeyCode(final int keyCode , final int delay , final boolean lock){ 
			if(lock){
				if(sendKeyLock){
					return;
				}
				 
				sendKeyLock = true;
			}
	        new Thread () {  
	            public void run() {  
	            	if(delay > 0){
	            		try {
							Thread.sleep(delay);
						} catch (InterruptedException e) {
							e.printStackTrace();
						}
	            	}
	                try {  
	                    Instrumentation inst = new Instrumentation();  
	                    inst.sendKeyDownUpSync(keyCode);  
	                    Log.i("sendKeyCode", "sendKeyDownUpSync:" + keyCode);
	                } catch (Exception e) {
	                    Log.e("sendKeyCode", "err:"+e.getMessage());
	                } finally{
	                	if(lock){
	                		sendKeyLock = false;
	                	}
	                } 
	            }  
	        }.start();  
	    }  
}
